package com.lft.freshordering.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lft.freshordering.entity.Goods;
import com.lft.freshordering.entity.Stypes;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author tyhxzy
 * @since 2024-12-02
 */
public interface GoodsMapper extends BaseMapper<Goods> {

    //根据商品得等查询
    @Select("select goods_id,goods_name,gjprices from goods where goods_id = #{gid}")
    Goods selectByid(Integer name);

    //用户删除购物车中的商品
    @Delete("delete from gocar where uid = #{uid} and sid = #{sid}")
    Integer deletebyids(Integer uid, Integer sid);

    @Select("select * from goods where is_deleted=0 and order by goods_id desc ")
    List<Goods> selectgoods();

    @Select("select * from goods where is_deleted=0 and category_id = #{categoryId} order by goods_id desc;")
    List<Goods> selectCategoryId(Integer categoryId);

    @Select("select * from stypes where id=#{id}")
    Stypes selectstype(Integer id);


    @Select("select * from goods,goods_unit,stypes where goods.goods_unit=goods_unit.unit_id and stypes.id=goods.category_id and goods.is_deleted=0 and goods.goods_id=#{id}")
    Goods getid(Integer id);

    Integer updategoods(Goods goods);

    Integer instertgoods(Goods goods);

    @Update("update goods set is_deleted=1 where goods_id=#{id}")
    int deletegoods(Integer id);


    @Select("select * from goods where is_eleted=0 and category_id=#{id}")
    List<Goods> selectGoodsByCategoryId(Integer id);


    @Update("update goods set goods_pics=#{goodsPics} where goods_id=#{goodsId}")
    int save(Goods gg);

    @Update("update goods set goods_pics=#{goodsPics} where goods_id=#{goodsId}")
    int updateimg(Goods gg);

    @Select("select * from goods where is_deleted=0 and goods_name like '%${search}%'")
    List<Goods> selectLike(String search);
}
